package com.spi.soconversion.base.data;

import java.io.File;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;

import com.spi.soconversion.base.SOCException;
import com.spi.soconversion.base.handlers.InstallBaseConversionErrorHandler;
import com.spi.soconversion.orders.SOCInstallBaseWarranty;
import com.spi.soconversion.orders.SOCInstallBaseWarrantyList;
import com.spi.soconversion.orders.conversion.CItemType;
import com.spi.soconversion.orders.conversion.InstallBase;
import com.spi.soconversion.orders.conversion.InstallBaseAssociation;
import com.spi.soconversion.orders.conversion.InstallBaseFulfillmentMethod;
import com.spi.soconversion.orders.conversion.InstallBaseFulfillmentStore;
import com.spi.soconversion.orders.conversion.InstallBaseFurnitureWarranty;
import com.spi.soconversion.orders.conversion.InstallBaseLineType;
import com.spi.soconversion.orders.conversion.InstallBaseNote;
import com.spi.soconversion.orders.conversion.InstallBaseNotes;
import com.spi.soconversion.orders.conversion.ItemInstallBase;
import com.spi.soconversion.orders.conversion.WarrantyInstallBase;
import com.spi.soconversion.util.DBConnection;
import com.spi.soconversion.util.ErrorConstants;
import com.spi.soconversion.util.ErrorMessageReader;
import com.spi.soconversion.util.QueryConstants;
import com.spi.soconversion.util.QueryReader;
import com.spi.soconversion.util.SOCConstants;
import com.spi.soconversion.util.SOCFileWriter;
import com.spi.soconversion.util.SOCUtility;

public class InstallBaseDataProcessor implements DataProcessor {

	private int d_batchSize;
	private int d_batchNum;
	private int d_totalRecProcessed;
	private String d_logFileName;
	private SOCFileWriter d_fileWriter;	
	private String d_xmlDirectory;
	private int d_xmlCounter;
	private int d_recordsFetched;
	private SOCInstallBaseWarrantyList extendedWarrantyList ;
	private SOCInstallBaseWarrantyList manufactureWarrantyList;
	private InstallBaseConversionErrorHandler errorHandler;
	private InstallBaseFurnitureWarranty furnitureWty;

	public InstallBaseDataProcessor(int batchSize, int totalRecProcessed, String logFileName, SOCFileWriter fileWriter, String xmlDirectory,int batchNum)
	{
		d_batchSize=batchSize;
		d_totalRecProcessed=totalRecProcessed;
		d_logFileName = logFileName;
		d_fileWriter = fileWriter;
		d_xmlDirectory = xmlDirectory;
		d_batchNum=batchNum;
		errorHandler= new InstallBaseConversionErrorHandler(d_logFileName,d_fileWriter);
	}

	public int processRecords() throws SOCException 
	{
		int result = 0;
		PreparedStatement installBaseStmt=null;
		PreparedStatement installBaseNoteStmt=null;  
		PreparedStatement installBaseWtyStmt=null;
		PreparedStatement installBaseGetOrderStmt=null;
		PreparedStatement installBaseFurnitureWtyStmt=null;
		long badRecords =0;
		ResultSet rsInstallBase=null;
		String furnitureWtySkuChk;
		String fetchInstallBaseQuery = null;
		d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(SOCConstants.MESSAGE_PROCESSING_INSTALL_BASE_STARTS));
		int recordsFetched=0;
		
		if(d_batchSize > 0)
		{
			fetchInstallBaseQuery = QueryReader.getQuery(QueryConstants.SELECT_FLAT_TABLE_INSTALLBASE_QUERY);
		}
		else{
			fetchInstallBaseQuery = QueryReader.getQuery(QueryConstants.SELECT_ALL_FLAT_TABLE_INSTALLBASE_QUERY);
		}

		String fetchInstallBaseNotesQuery = QueryReader.getQuery(QueryConstants.SELECT_FLAT_TABLE_INSTALLBASE_NOTES_QUERY);
		String fetchInstallBaseWtyQuery = QueryReader.getQuery(QueryConstants.SELECT_FLAT_TABLE_INSTALLBASE_WTY_QUERY);
		String fetchInstallBaseOrder = QueryReader.getQuery(QueryConstants.INSTALL_BASE_FIND_ORDER);
		String fetchInstallBaseOrderLines = QueryReader.getQuery(QueryConstants.INSTALL_BASE_FIND_ORDER_LINES);
				
		try 
		{

			installBaseStmt=DBConnection.getConnection().prepareStatement(fetchInstallBaseQuery);
			installBaseNoteStmt=DBConnection.getConnection().prepareStatement(fetchInstallBaseNotesQuery);
			installBaseWtyStmt=DBConnection.getConnection().prepareStatement(fetchInstallBaseWtyQuery);
			installBaseGetOrderStmt=DBConnection.getConnection().prepareStatement(fetchInstallBaseOrder);
			installBaseFurnitureWtyStmt=DBConnection.getConnection().prepareStatement(fetchInstallBaseOrderLines);
			
			// Change this line when testng to create xml for particular record
		    d_totalRecProcessed=3218604;
			installBaseStmt.setInt(1, d_totalRecProcessed+1);
			if(d_batchSize>0)
			{
				installBaseStmt.setInt(2, d_totalRecProcessed+d_batchSize);
			}

			rsInstallBase=installBaseStmt.executeQuery();

			long instanceId=-1;

			while(rsInstallBase.next())
			{		
				recordsFetched++;
				ItemInstallBase iBase=new ItemInstallBase();	
				boolean badRecord=false;
				try
				{
					//Row is fetched from the database and assigned to installbase object
					instanceId =rsInstallBase.getInt("INSTANCEID");
					
					iBase.setInstanceId(String.valueOf(instanceId));

					String address = rsInstallBase.getString("ADDRESS");
				
					String addLine1 = "";
					String addLine2 = "";
					String addLine3 = "";
					String addLine4 = "";
					String addLine5 = "";
					if(address != null)
					{
						if(address.length() <= 70)
						{
							addLine1 = address.substring(0, address.length());
						}
						else if(address.length() <= 140)
						{
							addLine1 = address.substring(0, 70);
							addLine2 = address.substring(70, address.length());
						}
						else if(address.length() <= 210)
						{
							addLine1 = address.substring(0, 70);
							addLine2 = address.substring(70,140);
							addLine3 = address.substring(140, address.length());
						}
						else if(address.length() <= 280)
						{
							addLine1 = address.substring(0, 70);
							addLine2 = address.substring(70,140);
							addLine3 = address.substring(140,210);
							addLine4 = address.substring(210, address.length());
						}
						else if(address.length() <= 350)
						{
							addLine1 = address.substring(0, 70);
							addLine2 = address.substring(70,140);
							addLine3 = address.substring(140,210);
							addLine4 = address.substring(210,280);
							addLine5 = address.substring(280, address.length());
						}
						else
						{
							addLine1 = address.substring(0, 70);
							addLine2 = address.substring(70,140);
							addLine3 = address.substring(140,210);
							addLine4 = address.substring(210,280);
							addLine5 = address.substring(280, 350);
						}
					}

					iBase.setAddLine1(addLine1);
					iBase.setAddLine2(addLine2);
					iBase.setAddLine3(addLine3);
					iBase.setAddLine4(addLine4);
					iBase.setAddLine5(addLine5);	

					String city=rsInstallBase.getString("CITY");
					iBase.setCity(city);		

					String state=rsInstallBase.getString("STATE");
					iBase.setState(state);

					String zipCode=rsInstallBase.getString("ZIPCODE");
					iBase.setZipCode(zipCode);

					Timestamp createTS = rsInstallBase.getTimestamp("CREATETS");
					if(createTS!=null)
					{
						iBase.setCreatets(SOCUtility.formatDate(createTS));
					}

					String createUserId =rsInstallBase.getString("CREATEUSERID");
					iBase.setCreateUserID(createUserId);

					String customerId = String.valueOf(rsInstallBase.getInt("OWNERPARTYID"));
					iBase.setCustomerID(customerId);

					String mobile = rsInstallBase.getString("MOBILENO");				
					iBase.setMobile(mobile);

					String dayFax = rsInstallBase.getString("DAYFAXNO");
					iBase.setDayFax(dayFax);

					String dayPhone = rsInstallBase.getString("DAYPHONENO");
					iBase.setDayPhone(dayPhone);

					String emailId = rsInstallBase.getString("EMAILID");
					iBase.setEmailID(emailId);

					String evePhone = rsInstallBase.getString("EVENINGPHONENO");
					iBase.setEvePhone(evePhone);

					String firstName = rsInstallBase.getString("FIRSTNAME");
					iBase.setFirstName(firstName);

					String lastName = rsInstallBase.getString("LASTNAME");
					iBase.setLastName(lastName);

					Timestamp fulFillmentDate = rsInstallBase.getTimestamp("FULLFILLMENTDATE");
					
					if(fulFillmentDate!=null)
					{
						iBase.setFulFillmentDate(SOCUtility.formatDate(fulFillmentDate));
					}
					
					String sellingStore = rsInstallBase.getString("SELLINGSTORE");
					iBase.setSellingStore(sellingStore);
					
					Long lineId = rsInstallBase.getLong("LINEID");
					
					String shippingMethod =  rsInstallBase.getString("SHIPPINGMETHOD");
				
					if(lineId>0 && shippingMethod==null)
					{
						shippingMethod=SOCConstants.DEFAULT_SHIPPING_METHOD_INSTALL_BASE;
					}
					
					String fulFillmentMethod = null;
					String fulFillmentStore = null;
					if(shippingMethod==null)
					{
						iBase.setFulFillmentMethod(SOCConstants.EMPTY_STRING);
						iBase.setFulFillmentStore(SOCConstants.EMPTY_STRING);
						iBase.setLineType(SOCConstants.EMPTY_STRING);
					}
					else
					{
						fulFillmentMethod = InstallBaseFulfillmentMethod.getMCFFulfillmentMethod(shippingMethod);
						if(fulFillmentMethod==null)
						{
							shippingMethod=SOCConstants.DEFAULT_SHIPPING_METHOD_INSTALL_BASE;
							fulFillmentMethod = InstallBaseFulfillmentMethod.getMCFFulfillmentMethod(shippingMethod);
						}
						
						iBase.setFulFillmentMethod(fulFillmentMethod);
						String dcStoreName = rsInstallBase.getString("ORGANIZATIONNAME");
						fulFillmentStore = InstallBaseFulfillmentStore.getMCFFulfillmentStore(shippingMethod);
						fulFillmentStore =fulFillmentStore ==null?"":fulFillmentStore;
					
						if("STORE".equals(fulFillmentStore))
						{
							iBase.setFulFillmentStore(sellingStore);
						}
						else if("DC".equals(fulFillmentStore))
						{
							if(dcStoreName!=null && dcStoreName.length()>4)
							{
								dcStoreName = dcStoreName.substring(0,4);
								int storeNum = 0;
								if(SOCUtility.isNumber(dcStoreName))
								{
									storeNum = Integer.parseInt(dcStoreName);
								}
								else
								{
									errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
											ErrorConstants.INVALID_ORGANIZATION_NAME_INSTALLBASE_CONVERSION)+dcStoreName, d_batchNum);
									badRecord=true;
									badRecords++;
									continue;
								}
								iBase.setFulFillmentStore(String.valueOf(storeNum));
							}
							else
							{
								errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
										ErrorConstants.INVALID_ORGANIZATION_NAME_INSTALLBASE_CONVERSION)+dcStoreName, d_batchNum);
								badRecord=true;
								badRecords++;
								continue;
							}
						}
						String lineType = InstallBaseLineType.getMCFLineType(shippingMethod);
						if(lineType==null)
						{
							errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
									ErrorConstants.INVALID_SHIPPING_METHOD_CODE_INSTALLBASE_CONVERSION)+shippingMethod, d_batchNum);
							badRecord=true;
							badRecords++;
							continue;
						}
						iBase.setLineType(lineType);
					}
					
					String itemDesc = rsInstallBase.getString("ITEMDESCRIPTION");
					iBase.setItemDesc(itemDesc);

					String itemId = rsInstallBase.getString("ITEMID");
					iBase.setItemID(itemId);

					String itemType = rsInstallBase.getString("ITEMTYPE");
					String mcfItemType = CItemType.getMCFItemType(itemType);
					
					if(mcfItemType==null)
					{
						errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
								ErrorConstants.INVALID_ITEM_TYPE_INSTALLBASE_CONVERSION)+itemType, d_batchNum);
						badRecord=true;
						badRecords++;
						continue;
					}
					iBase.setItemType(mcfItemType);
					String lifeExpectancy = rsInstallBase.getString("LIFEEXPECTANCY");
					if(lifeExpectancy!=null )
					{
						if(SOCUtility.isNumber(lifeExpectancy))
						{
							int lifeExpectancyInDays = Integer.parseInt(lifeExpectancy)*SOCConstants.DAYS_IN_YEAR;
							iBase.setLifeExpectancy(String.valueOf(lifeExpectancyInDays));
						}
						else
						{
							iBase.setLifeExpectancy(SOCConstants.DEFAULT_LIFEEXPECTANCY);
						}
					}
					else
					{
						iBase.setLifeExpectancy(SOCConstants.DEFAULT_LIFEEXPECTANCY);
					}
					String orderNum = String.valueOf(rsInstallBase.getLong("ORDERNO"));
					orderNum= "0".equals( orderNum )?"":orderNum;
					iBase.setOrderNo(orderNum);

					String posRegister = rsInstallBase.getString("POSREGISTERID");
					iBase.setPosRegister(posRegister);

					String posTransDate = rsInstallBase.getString("POSTRANSDATE");
					if(posTransDate!= null)
					{
						String validPOSDate = SOCUtility.getValidDate(posTransDate);
						if(validPOSDate!=null)					
						{
							iBase.setPosTransDate(validPOSDate);
						}
						else
						{
							errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
									ErrorConstants.INVALID_POS_TRANS_DATE_INSTALLBASE_CONVERSION)+posTransDate, d_batchNum);
							badRecord=true;
							badRecords++;
							continue;
						}
					}
					else
					{
						iBase.setPosTransDate(SOCConstants.EMPTY_STRING);
					}

					String posTransId = rsInstallBase.getString("POSTRANSID");
					iBase.setPosTransID(posTransId);

					// If quantity is negative then that instanceid should be ignored from processing
					// --Start of removing negative quantity/Ganesh/30-Jun-2010
					if(rsInstallBase.getInt("QUANTITY")>0)
					{
						String quantity = String.valueOf(rsInstallBase.getInt("QUANTITY"));
						iBase.setQuantity(quantity);
					}
					else
					{
						errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
								ErrorConstants.NEGATIVE_QUANTITY_FOR_INSTANCE_ID), d_batchNum);
						badRecord=true;
						badRecords++;
						continue;
					}
					// --End of removing negative quantity/Ganesh/30-Jun-2010

					String sellingPrice = rsInstallBase.getString("SELLINGPRICE");
					iBase.setSellingPrice(sellingPrice);

					getWarranty(instanceId,installBaseWtyStmt);
					SOCInstallBaseWarranty manufactureWarranty = null;
					
					if(manufactureWarrantyList!=null)
					{
						manufactureWarranty=manufactureWarrantyList.getInstallBaseWarranty("WARRANTY");
						
						if(manufactureWarranty!=null)
						{
							Timestamp startDate = manufactureWarranty.getWarrantyStartDate();
							
							if(startDate!=null)					
							{								
								iBase.setManuStartDate(SOCUtility.formatDate(startDate));
							}
							else
							{
								errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
										ErrorConstants.MISSING_MANU_WTYSTARTDATE_INSTALLBASE_CONVERSION), d_batchNum);
								badRecord=true;
								badRecords++;
								continue;
							}
							
							Timestamp endDate = manufactureWarranty.getWarrantyEndDate();
							
							if(endDate!=null)					
							{
								iBase.setManuEndDate(SOCUtility.formatDate(endDate));
							}
							else
							{
								errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
										ErrorConstants.MISSING_MANU_WTYENDDATE_INSTALLBASE_CONVERSION), d_batchNum);
								badRecord=true;
								badRecords++;
								continue;
							}				
							iBase.setWarrantyDuration(String.valueOf(SOCUtility.daysBetween(startDate,endDate)));
						} else {						
							iBase.setManuStartDate(SOCUtility.formatDate(fulFillmentDate));
							iBase.setManuEndDate(SOCUtility.addYearToDate(fulFillmentDate));
						}
					} 
					
					SOCInstallBaseWarranty extendedWarranty = null;
					if(extendedWarrantyList!=null)
					{
						extendedWarranty=extendedWarrantyList.getInstallBaseWarranty("EXT_WARRANTY");
						
						if(extendedWarranty!=null)
						{
							InstallBaseAssociation ibAssoc=iBase.getInstallBaseAssociation();
							ibAssoc.setCreatets(SOCUtility.formatDate(createTS));
							ibAssoc.setCreateUserID(createUserId);
							Timestamp startDate = extendedWarranty.getWarrantyStartDate();
							
							if(startDate!=null)					
							{
								ibAssoc.setWarrantyStart(SOCUtility.formatDate(startDate));
							}
							else
							{
								errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
										ErrorConstants.MISSING_EXT_WTYSTARTDATE_INSTALLBASE_CONVERSION), d_batchNum);
								badRecord=true;
								badRecords++;
								continue;
							}
							Timestamp endDate = extendedWarranty.getWarrantyEndDate();
							if(endDate!=null)					
							{
								ibAssoc.setWarrantyEnd(SOCUtility.formatDate(extendedWarranty.getWarrantyEndDate()));
							}
							else
							{
								errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
										ErrorConstants.MISSING_EXT_WTYENDDATE_INSTALLBASE_CONVERSION), d_batchNum);
								badRecord=true;
								badRecords++;
								continue;
							}						
							
							ibAssoc.isExtendedWarranty(true);
							WarrantyInstallBase assocInstallBase = ibAssoc.getWarrantyInstallBase();
							assocInstallBase.setWarrantyDuration(String.valueOf(SOCUtility.daysBetween(startDate,endDate)));
							assocInstallBase.setInstanceId(String.valueOf(instanceId));
							assocInstallBase.setAddLine1(addLine1);
							assocInstallBase.setAddLine2(addLine2);
							assocInstallBase.setAddLine3(addLine3);
							assocInstallBase.setAddLine4(addLine4);
							assocInstallBase.setAddLine5(addLine5);
							assocInstallBase.setCity(city);
							assocInstallBase.setZipCode(zipCode);
							assocInstallBase.setState(state);
							if(createTS!=null)
							{
								assocInstallBase.setCreatets(SOCUtility.formatDate(createTS));
							}
							assocInstallBase.setCreateUserID(createUserId);
							assocInstallBase.setCustomerID(customerId);
							assocInstallBase.setDayFax(dayFax);
							assocInstallBase.setDayPhone(dayPhone);
							assocInstallBase.setEvePhone(evePhone);
							assocInstallBase.setEmailID(emailId);
							assocInstallBase.setMobile(mobile);
							assocInstallBase.setFirstName(firstName);
							assocInstallBase.setLastName(lastName);
							if(fulFillmentDate!=null)
							{
								assocInstallBase.setFulFillmentDate(SOCUtility.formatDate(fulFillmentDate));
							}
							assocInstallBase.setFulFillmentMethod(iBase.getFulFillmentMethod());
							assocInstallBase.setFulFillmentStore(iBase.getFulFillmentStore());
							assocInstallBase.setItemDesc(extendedWarranty.getWarrantyDescription());
							furnitureWtySkuChk= extendedWarranty.getWarrantySKU();
							
							if(SOCConstants.INSTALL_BASE_FURNITURE_WTY_CONST1.equals(furnitureWtySkuChk) || SOCConstants.INSTALL_BASE_FURNITURE_WTY_CONST2.equals(furnitureWtySkuChk)|| SOCConstants.INSTALL_BASE_FURNITURE_WTY_CONST3.equals(furnitureWtySkuChk))
							{
								furnitureWty=getFurnitureWarranty(instanceId, furnitureWtySkuChk, installBaseGetOrderStmt, installBaseFurnitureWtyStmt, lineId);
								assocInstallBase.setItemID(furnitureWty.getWarrantySku());
								assocInstallBase.setSellingPrice(String.valueOf(furnitureWty.getUnitPrice()));
							}
							else
							{
								assocInstallBase.setItemID(extendedWarranty.getWarrantySKU());
								assocInstallBase.setSellingPrice(extendedWarranty.getWarrantyPrice());
							}
							
							assocInstallBase.setItemType(SOCConstants.ITEM_TYPE_WARRANTY);
							assocInstallBase.setLifeExpectancy(SOCConstants.ZERO);
							assocInstallBase.setLineType(SOCConstants.LINE_TYPE_WARRANTY);
							assocInstallBase.setOrderNo(iBase.getOrderNo());
							assocInstallBase.setPosRegister(iBase.getPosRegister());
							if(posTransDate!=null)
							{
								assocInstallBase.setPosTransDate(iBase.getPosTransDate());
							}
							assocInstallBase.setPosTransID(posTransId);
							assocInstallBase.setQuantity(iBase.getQuantity());
							
							assocInstallBase.setSellingStore(iBase.getSellingStore());
						}
					}
					
					InstallBaseNotes ibNotes=getNotes(instanceId,installBaseNoteStmt);
					
					if(ibNotes!=null)
					{
						iBase.setInstallBaseNotes(ibNotes);
					}	
					boolean validData = validateItemInstallBase(iBase);
					if(validData)
					{
						writeInstallBaseXML(iBase);	
					}
					else
					{
						badRecord=true;
						badRecords++;
						continue;
					}

				}
				catch (SQLException sqle) {

					sqle.printStackTrace();
					d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
							ErrorConstants.FAILED_RECORD_PROCESS_FLATTABLE_INSTALL_BASE)+instanceId+SOCConstants.NEW_LINE+sqle.getMessage()));
					throw new SOCException(
							ErrorMessageReader.getError(
									ErrorConstants.FAILED_RECORD_PROCESS_FLATTABLE_INSTALL_BASE) + instanceId ,sqle);
				}


			}
			
			errorHandler.updateErrors();
			
			if(d_batchSize==0)
			{
				result=d_totalRecProcessed+recordsFetched;
			}
			else
			{
				result=d_totalRecProcessed+d_batchSize;
			}
			d_recordsFetched = recordsFetched;
			
			d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(SOCConstants.MESSAGE_PROCESSING_INSTALL_BASE_ENDS));
			return result;
					
		} 

		catch (SQLException se) 
		{
			d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
					ErrorConstants.FAILED_DATA_PROCESS_INSTALL_BASE)+SOCConstants.NEW_LINE+se.getMessage()));
			throw new SOCException(
					ErrorMessageReader.getError(
							ErrorConstants.FAILED_DATA_PROCESS_INSTALL_BASE),se);
		}
		finally
		{
			try {

				if(rsInstallBase!=null)
				{
					rsInstallBase.close();
				}
			}
			catch (SQLException sqle) 
			{
				d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
						ErrorConstants.FAILED_CLOSE_RESULTSET_FLATTABLE_INSTALL_BASE)+SOCConstants.NEW_LINE+sqle.getMessage()));
				throw new SOCException(
						ErrorMessageReader.getError(
								ErrorConstants.FAILED_CLOSE_RESULTSET_FLATTABLE_INSTALL_BASE),sqle);
			}
			try {

				if(installBaseStmt!=null)
				{
					installBaseStmt.close();
				}
			}
			catch (SQLException sqle) 
			{
				d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
						ErrorConstants.FAILED_CLOSE_STATEMENT_FLATTABLE_INSTALL_BASE)+SOCConstants.NEW_LINE+sqle.getMessage()));
				throw new SOCException(
						ErrorMessageReader.getError(
								ErrorConstants.FAILED_CLOSE_STATEMENT_FLATTABLE_INSTALL_BASE),sqle);
			}
			try {

				if(installBaseNoteStmt!=null)
				{
					installBaseNoteStmt.close();
				}
			}
			catch (SQLException sqle) 
			{
				d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
						ErrorConstants.FAILED_CLOSE_STATEMENT_FLATTABLE_INSTALL_BASE_NOTES)+SOCConstants.NEW_LINE+sqle.getMessage()));
				throw new SOCException(
						ErrorMessageReader.getError(
								ErrorConstants.FAILED_CLOSE_STATEMENT_FLATTABLE_INSTALL_BASE_NOTES),sqle);
			}
			try {

				if(installBaseWtyStmt!=null)
				{
					installBaseWtyStmt.close();
				}
			}
			catch (SQLException sqle) 
			{
				d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
						ErrorConstants.FAILED_CLOSE_STATEMENT_FLATTABLE_INSTALL_BASE_WTY)+SOCConstants.NEW_LINE+sqle.getMessage()));
				throw new SOCException(
						ErrorMessageReader.getError(
								ErrorConstants.FAILED_CLOSE_STATEMENT_FLATTABLE_INSTALL_BASE_WTY),sqle);
			}
			try {

				if(installBaseGetOrderStmt!=null)
				{
					installBaseGetOrderStmt.close();
				}
			}
			catch (SQLException sqle) 
			{
				d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
						ErrorConstants.FAILED_CLOSE_STATEMENT_FLATTABLE_INSTALL_BASE_WTY)+SOCConstants.NEW_LINE+sqle.getMessage()));
				throw new SOCException(
						ErrorMessageReader.getError(
								ErrorConstants.FAILED_CLOSE_STATEMENT_FLATTABLE_INSTALL_BASE_WTY),sqle);
			}
			try {

				if(installBaseFurnitureWtyStmt!=null)
				{
					installBaseFurnitureWtyStmt.close();
				}
			}
			catch (SQLException sqle) 
			{
				d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
						ErrorConstants.FAILED_CLOSE_STATEMENT_FLATTABLE_INSTALL_BASE_WTY)+SOCConstants.NEW_LINE+sqle.getMessage()));
				throw new SOCException(
						ErrorMessageReader.getError(
								ErrorConstants.FAILED_CLOSE_STATEMENT_FLATTABLE_INSTALL_BASE_WTY),sqle);
			}
		}
	}
	
	public int getRecordsFetched()
	{
		return d_recordsFetched;
	}
	
	public int getCountXMLCreated()
	{
		return d_xmlCounter;
	}
	
	private void writeInstallBaseXML(ItemInstallBase iBase) throws SOCException
	{
		int childDir = getChildDirectory();
		File childDirRef= new File(d_xmlDirectory+SOCConstants.DELIMITER+childDir);
    	if (!childDirRef.exists())
        {
    		childDirRef.mkdir();    	
    	}
		String xmlFileName= childDirRef.getAbsolutePath()+SOCConstants.DELIMITER +SOCConstants.INSTALL_BASE_XML_FILE+iBase.getInstanceId()+SOCConstants.XML_FILE_EXTN;
		String installBaseRec = iBase.toString();
		
		d_fileWriter.write(xmlFileName,installBaseRec);    	
		d_fileWriter.closeFile(xmlFileName);
		d_xmlCounter++;
	}

    private int getChildDirectory()
    {
    	int result = 0;
    	int division = ((d_xmlCounter+1)/SOCConstants.MAXIMUM_FILE_COUNT);
    	int reminder = ((d_xmlCounter+1)%SOCConstants.MAXIMUM_FILE_COUNT);
    	
    	if(reminder>0)
    	{
    		result = division+1;
    	}
    	else
    	{
    		result = division;
    	}
    	
    	return result;
    }
    
    private InstallBaseNotes getNotes(long instanceID,PreparedStatement installBaseNoteStmt) throws SOCException
    {

    	ResultSet rsInstallBaseNotes=null;

		// Row is fetched from database and assigned to installBaseNote object
		InstallBaseNotes ibNotes=null;
		try
		{
			installBaseNoteStmt.setLong(1, instanceID);
			rsInstallBaseNotes=installBaseNoteStmt.executeQuery();

			InstallBaseNote ibNote=null;

			if(rsInstallBaseNotes!=null )
			{
				ibNotes=new InstallBaseNotes();
			}
			while(rsInstallBaseNotes.next())
			{
				ibNote=new InstallBaseNote();
				Timestamp createTsNotes = rsInstallBaseNotes.getTimestamp("CREATETS");
				if(createTsNotes!=null)
				{
					ibNote.setCreatets(SOCUtility.formatDate(createTsNotes));
				}
				ibNote.setCreateUserID(rsInstallBaseNotes.getString("CREATEUSERID"));
				ibNote.setNoteText(rsInstallBaseNotes.getString("INSTALLBASENOTETEXT"));					

				ibNotes.addInstallBaseNote(ibNote);

			}
		}
		catch(SQLException sqle)
		{
			d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
					ErrorConstants.FAILED_RECORD_PROCESS_FLATTABLE_INSTALL_BASE_NOTES)+ instanceID+SOCConstants.NEW_LINE+sqle.getMessage()));
			throw new SOCException(
					ErrorMessageReader.getError(
							ErrorConstants.FAILED_RECORD_PROCESS_FLATTABLE_INSTALL_BASE_NOTES) + instanceID ,sqle);

		}	
		finally
		{
			try {

				if(rsInstallBaseNotes!=null)
				{
					rsInstallBaseNotes.close();
				}
			}
			catch (SQLException sqle) 
			{
				d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
						ErrorConstants.FAILED_CLOSE_RESULTSET_FLATTABLE_INSTALL_BASE_NOTES)+SOCConstants.NEW_LINE+sqle.getMessage()));
				throw new SOCException(
						ErrorMessageReader.getError(
								ErrorConstants.FAILED_CLOSE_RESULTSET_FLATTABLE_INSTALL_BASE_NOTES),sqle);
			}					
		}
		return ibNotes;
    }

    private void getWarranty(long instanceID,PreparedStatement installBaseWtyStmt) throws SOCException
    {
    	
    	ResultSet rsInstallBaseWty=null;
    	
    	try
		{
    		installBaseWtyStmt.setLong(1, instanceID);
    		rsInstallBaseWty=installBaseWtyStmt.executeQuery();

    		SOCInstallBaseWarranty ibWty=null;

			if(rsInstallBaseWty!=null )
			{
				extendedWarrantyList=new SOCInstallBaseWarrantyList();
				manufactureWarrantyList= new SOCInstallBaseWarrantyList();
			}
			
			while(rsInstallBaseWty.next())
			{
				ibWty=new SOCInstallBaseWarranty();
				ibWty.setWarrantyStartDate(rsInstallBaseWty.getTimestamp("HEADERSTARTDATE"));
				ibWty.setWarrantyEndDate(rsInstallBaseWty.getTimestamp("HEADERENDDATE"));
				ibWty.setWarrantyStatus(rsInstallBaseWty.getString("STATUSCODE"));
				ibWty.setWarrantyDescription(rsInstallBaseWty.getString("WTYDESCRIPTION"));
				ibWty.setWarrantyPrice(rsInstallBaseWty.getString("HEADERCONTRACTAMT"));
				ibWty.setWarrantySKU(rsInstallBaseWty.getString("WTYSKU"));
				String wtyType= rsInstallBaseWty.getString("WTYTYPE");
				
				if("EXT_WARRANTY".equals(wtyType))
				{
					extendedWarrantyList.addInstallBaseWarranty(ibWty);
				}
				else if("WARRANTY".equals(wtyType))
				{
					manufactureWarrantyList.addInstallBaseWarranty(ibWty);
				}
			}
			
		}
		catch(SQLException sqle)
		{
			d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
					ErrorConstants.FAILED_RECORD_PROCESS_FLATTABLE_INSTALL_BASE_WTY)+ instanceID+SOCConstants.NEW_LINE+sqle.getMessage()));
			throw new SOCException(
					ErrorMessageReader.getError(
							ErrorConstants.FAILED_RECORD_PROCESS_FLATTABLE_INSTALL_BASE_WTY) + instanceID ,sqle);

		}	
		finally
		{
			try {

				if(rsInstallBaseWty!=null)
				{
					rsInstallBaseWty.close();
				}
			}
			catch (SQLException sqle) 
			{
				d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
						ErrorConstants.FAILED_CLOSE_RESULTSET_FLATTABLE_INSTALL_BASE_WTY)+SOCConstants.NEW_LINE+sqle.getMessage()));
				throw new SOCException(
						ErrorMessageReader.getError(
								ErrorConstants.FAILED_CLOSE_RESULTSET_FLATTABLE_INSTALL_BASE_WTY),sqle);
			}					
		}
    }
    
    /*
     * This method returns furniture warrany object which will have warranty sku and unit selling price.
     */
    
    private InstallBaseFurnitureWarranty getFurnitureWarranty(Long instanceID,String furnitureWtySkuChk,PreparedStatement installBaseGetOrderStmt,PreparedStatement installBaseWtyStmt,Long lineId) throws SOCException
    {
    	
    	ResultSet rsInstallBaseFurWtyOrder=null;
    	ResultSet rsInstallBaseFurWtyLines=null;
    	Long headerId;
    	String lineType;
    	String lineCategory;
    	String type;
    	String wtySku;
    	Float unitPrice;
    	
    	InstallBaseFurnitureWarranty furWty=new InstallBaseFurnitureWarranty();
    	try
		{
    		if(SOCConstants.INSTALL_BASE_FURNITURE_WTY_CONST1.equals(furnitureWtySkuChk))
			{
				if(lineId==null)
				{
					furWty.setWarrantySku(SOCConstants.INSTALL_BASE_FURNITURE_WTY_REPLACE_CONST1);
				}
				else 
				{
					installBaseGetOrderStmt.setLong(1, lineId);
					rsInstallBaseFurWtyOrder = installBaseGetOrderStmt.executeQuery();
					if(rsInstallBaseFurWtyOrder.next())
					{
						headerId=rsInstallBaseFurWtyOrder.getLong("HEADER_ID");
						installBaseWtyStmt.setLong(1, headerId);
						rsInstallBaseFurWtyLines=installBaseWtyStmt.executeQuery();
						while(rsInstallBaseFurWtyLines.next())
						{
							type=rsInstallBaseFurWtyLines.getString("ITEM_TYPE");
							if("WRFEE".equals(type))
							{
								lineType=rsInstallBaseFurWtyLines.getString("LINE_TYPE_ID");
								lineCategory=rsInstallBaseFurWtyLines.getString("LINE_CATEGORY_CODE");
								wtySku=rsInstallBaseFurWtyLines.getString("ORDERED_ITEM");
								unitPrice=rsInstallBaseFurWtyLines.getFloat("UNIT_SELLING_PRICE");
								if(!("1006".equals(lineType) || "1007".equals(lineType)) && !"RETURN".equals(lineCategory))
								{
									furWty.setWarrantySku(wtySku);
									furWty.setUnitPrice(unitPrice);
									break;
								}
							}
							
							
						}
					}
					else
					{
						furWty.setWarrantySku(SOCConstants.INSTALL_BASE_FURNITURE_WTY_REPLACE_CONST1);
					}
					
					
				}
			}
			else if(SOCConstants.INSTALL_BASE_FURNITURE_WTY_CONST2.equals(furnitureWtySkuChk))
			{
				if(lineId==null)
				{
					furWty.setWarrantySku(SOCConstants.INSTALL_BASE_FURNITURE_WTY_REPLACE_CONST2);
				}
				else 
				{
					installBaseGetOrderStmt.setLong(1, lineId);
					rsInstallBaseFurWtyOrder = installBaseGetOrderStmt.executeQuery();
					if(rsInstallBaseFurWtyOrder.next())
					{
						headerId=rsInstallBaseFurWtyOrder.getLong("HEADER_ID");
						installBaseWtyStmt.setLong(1, headerId);
						rsInstallBaseFurWtyLines=installBaseWtyStmt.executeQuery();
						while(rsInstallBaseFurWtyLines.next())
						{
							type=rsInstallBaseFurWtyLines.getString("ITEM_TYPE");
							if("WRFEE".equals(type))
							{
								lineType=rsInstallBaseFurWtyLines.getString("LINE_TYPE_ID");
								lineCategory=rsInstallBaseFurWtyLines.getString("LINE_CATEGORY_CODE");
								wtySku=rsInstallBaseFurWtyLines.getString("ORDERED_ITEM");
								unitPrice=rsInstallBaseFurWtyLines.getFloat("UNIT_SELLING_PRICE");
								if(!("1006".equals(lineType) || "1007".equals(lineType)) && !"RETURN".equals(lineCategory))
								{
									furWty.setWarrantySku(wtySku);
									furWty.setUnitPrice(unitPrice);
									break;
								}
							}
							
							
						}
					}
					else
					{
						furWty.setWarrantySku(SOCConstants.INSTALL_BASE_FURNITURE_WTY_REPLACE_CONST2);
					}
				}
			}
			else if(SOCConstants.INSTALL_BASE_FURNITURE_WTY_CONST3.equals(furnitureWtySkuChk))
			{
				if(lineId==null)
				{
					furWty.setWarrantySku(SOCConstants.INSTALL_BASE_FURNITURE_WTY_REPLACE_CONST3);
				}
				{
					installBaseGetOrderStmt.setLong(1, lineId);
					rsInstallBaseFurWtyOrder = installBaseGetOrderStmt.executeQuery();
					if(rsInstallBaseFurWtyOrder.next())
					{
						headerId=rsInstallBaseFurWtyOrder.getLong("HEADER_ID");
						installBaseWtyStmt.setLong(1, headerId);
						rsInstallBaseFurWtyLines=installBaseWtyStmt.executeQuery();
						while(rsInstallBaseFurWtyLines.next())
						{
							type=rsInstallBaseFurWtyLines.getString("ITEM_TYPE");
							if("WRFEE".equals(type))
							{
								lineType=rsInstallBaseFurWtyLines.getString("LINE_TYPE_ID");
								lineCategory=rsInstallBaseFurWtyLines.getString("LINE_CATEGORY_CODE");
								wtySku=rsInstallBaseFurWtyLines.getString("ORDERED_ITEM");
								unitPrice=rsInstallBaseFurWtyLines.getFloat("UNIT_SELLING_PRICE");
								if(!("1006".equals(lineType) || "1007".equals(lineType)) && !"RETURN".equals(lineCategory))
								{
									furWty.setWarrantySku(wtySku);
									furWty.setUnitPrice(unitPrice);
									break;
								}
							}
							
							
						}
					}
					else
					{
						furWty.setWarrantySku(SOCConstants.INSTALL_BASE_FURNITURE_WTY_REPLACE_CONST3);
					}
				}
			}
			
		}
		catch(SQLException sqle)
		{
			d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
					ErrorConstants.FAILED_RECORD_PROCESS_FLATTABLE_INSTALL_BASE_WTY)+ instanceID+SOCConstants.NEW_LINE+sqle.getMessage()));
			throw new SOCException(
					ErrorMessageReader.getError(
							ErrorConstants.FAILED_RECORD_PROCESS_FLATTABLE_INSTALL_BASE_WTY) + instanceID ,sqle);

		}	
		finally
		{
			try {

				if(rsInstallBaseFurWtyOrder!=null)
				{
					rsInstallBaseFurWtyOrder.close();
					
				}
				if(rsInstallBaseFurWtyLines!=null)
				{
					
					rsInstallBaseFurWtyLines.close();
				}
			}
			catch (SQLException sqle) 
			{
				d_fileWriter.write(d_logFileName, SOCUtility.writeLogMessage(ErrorMessageReader.getError(
						ErrorConstants.FAILED_CLOSE_RESULTSET_FLATTABLE_INSTALL_BASE_WTY)+SOCConstants.NEW_LINE+sqle.getMessage()));
				throw new SOCException(
						ErrorMessageReader.getError(
								ErrorConstants.FAILED_CLOSE_RESULTSET_FLATTABLE_INSTALL_BASE_WTY),sqle);
			}					
		}
		return furWty;
    }
   private boolean validateItemInstallBase(ItemInstallBase iBase) throws SOCException 
   {
	   boolean result=true;
	   if(iBase!=null)
   		{
		    result=validateInstallBase(iBase);
			long  instanceId = Long.parseLong(iBase.getInstanceId());
   			
   			InstallBaseAssociation iba = iBase.getInstallBaseAssociation();
   			if(iba!=null && iba.getIsExtendedWarranty()){
   				result = validateInstallBaseAssociation(iba,instanceId);
   			}
   			
   		}
	
	   return result;
   }
   
    private boolean validateInstallBase(InstallBase iBase) throws SOCException
    {
    	boolean result=true;
    
    	if(iBase!=null)
    	{
    		long  instanceId = Long.parseLong(iBase.getInstanceId());
    		
    		String custId=iBase.getCustomerID();
    		if(custId.length()==0)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
						ErrorConstants.MISSING_CUSTOMERID_INSTALLBASE_CONVERSION), d_batchNum);
    			return false;
    		}
    		if(custId.length()>40)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
						ErrorConstants.INVALID_CUSTOMERID_INSTALLBASE_CONVERSION)+iBase.getCustomerID(), d_batchNum);
    			return false;
    		}    		
    		if(iBase.getMobile().length()>40)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
						ErrorConstants.INVALID_MOBILE_INSTALLBASE_CONVERSION)+iBase.getMobile(), d_batchNum);
    			return false;
    		}
    		if(iBase.getDayFax().length()>40)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
						ErrorConstants.INVALID_DAYFAX_INSTALLBASE_CONVERSION)+iBase.getDayFax(), d_batchNum);
    			return false;
    		}
    		if(iBase.getDayPhone().length()>40)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
						ErrorConstants.INVALID_DAYPHONE_INSTALLBASE_CONVERSION)+iBase.getDayPhone(), d_batchNum);
    			return false;
    		}    		
    		if(iBase.getEvePhone().length()>40)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
						ErrorConstants.INVALID_EVEPHONE_INSTALLBASE_CONVERSION)+iBase.getEvePhone(), d_batchNum);
    			return false;
    		}    	
    	
    		if(iBase.getFulFillmentStore().length()>40)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
						ErrorConstants.INVALID_FULFILLMENTSTORE_INSTALLBASE_CONVERSION)+iBase.getFulFillmentStore(), d_batchNum);
    			return false;
    		}    		
    		String itemId=iBase.getItemID();
    		if(itemId.length()==0)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
						ErrorConstants.MISSING_ITEMID_INSTALLBASE_CONVERSION), d_batchNum);
    			return false;
    		}
    		if(itemId.length()>40)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
						ErrorConstants.INVALID_ITEMID_INSTALLBASE_CONVERSION)+iBase.getItemID(), d_batchNum);
    			return false;
    		}
    	
    		String itemType=SOCUtility.checkNull(iBase.getItemType());
    		
    		if(itemType.length()==0)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
						ErrorConstants.MISSING_ITEMTYPE_INSTALLBASE_CONVERSION), d_batchNum);
    			return false;
    		} 	
    		if(iBase.getOrderNo().length()>40)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
    					ErrorConstants.INVALID_ORDERNUMBER_INSTALLBASE_CONVERSION)+iBase.getOrderNo(), d_batchNum);
    			return false;
    		}
    		if(iBase.getPosRegister().length()>40)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
    					ErrorConstants.INVALID_POSREGISTERID_INSTALLBASE_CONVERSION)+iBase.getPosRegister(), d_batchNum);
    			return false;
    		}	
    		if(iBase.getPosTransID().length()>40)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
    					ErrorConstants.INVALID_POSTRANSID_INSTALLBASE_CONVERSION)+iBase.getPosTransID(), d_batchNum);
    			return false;
    		}
    		String quantity = iBase.getQuantity();
    		if(SOCConstants.EMPTY_STRING.equals(quantity))
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
    					ErrorConstants.MISIING_QUANTITY_INSTALLBASE_CONVERSION), d_batchNum);
    			return false;
    		}
    		else
    		{
	    		double qty =0;
	    		try
	    		{
	    			qty = Double.parseDouble(quantity);
	    		}
	    		catch(NumberFormatException nfe)
	    		{
	    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
	    					ErrorConstants.INVALID_QUANTITY_INSTALLBASE_CONVERSION)+quantity, d_batchNum);
	    			return false;
	    		}
	    	
	    		if(quantity.indexOf(".")!=-1 )
	    		{
	    			quantity=quantity.substring(0,quantity.indexOf("."));
	    		}
	    		if(quantity.length()>14)
	        		
	    		{
	    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
	    					ErrorConstants.INVALID_QUANTITY_LENGTH_INSTALLBASE_CONVERSION)+quantity, d_batchNum);
	    			return false;
	    		}
    		}
    		String sellingPrice = iBase.getSellingPrice();
    		double sp =0;
    		
    		if(sellingPrice.length()!=0)
    		{
    			try
	    		{
	    			sp = Double.parseDouble(sellingPrice);
	    		}
	    		catch(NumberFormatException nfe)
	    		{
	    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
	    					ErrorConstants.INVALID_SELLINGPRICE_INSTALLBASE_CONVERSION)+sellingPrice, d_batchNum);
	    			return false;
	    		}
	    		String floatSP="";
	    		if(sellingPrice.indexOf(".")!=-1 )
	    		{
	    			floatSP=sellingPrice.substring(sellingPrice.indexOf(".")+1,sellingPrice.length());
	    			sellingPrice=sellingPrice.substring(0,sellingPrice.indexOf("."));    			
	    		}
	    		if(sellingPrice.length()>19 || floatSP.length()>6)
	        		
	    		{
	    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
	    					ErrorConstants.INVALID_SELLINGPRICE_LENGTH_INSTALLBASE_CONVERSION)+sellingPrice, d_batchNum);
	    			return false;
	    		}
    	    }
    		if(iBase.getSellingStore().length()>40)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
    					ErrorConstants.INVALID_SELLINGSTORE_INSTALLBASE_CONVERSION)+iBase.getSellingStore(), d_batchNum);
    			return false;
    		}
    		if(iBase.getWarrantyDuration().length()>14)
        		
    		{
    			errorHandler.addErrors(instanceId, ErrorMessageReader.getError(
    					ErrorConstants.INVALID_WARRANTY_DURATION_INSTALLBASE_CONVERSION)+iBase.getWarrantyDuration(), d_batchNum);
    			return false;
    		}    		
    	}
    	
    	return result;
    }
    
    private boolean validateInstallBaseAssociation(InstallBaseAssociation iba,long instanceId) throws SOCException
    {
    	boolean result=true;
    	WarrantyInstallBase wtyIB = iba.getWarrantyInstallBase();
    	if(wtyIB!=null)
    	{
    		validateInstallBase(wtyIB);
    	}    
    	
    	return result;
    }	
  
  }
    

